﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WangMiEntity.EmployeeService;
using WangMiBusiness.GridViewModel;
using TaoBaoServices;

namespace WangMiBusiness.EmployeeService
{
    public class ManYiDuBusiness
    {
        /// <summary>
        /// 按日期排列
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        public List<ManYiDuDateEntity> GetManYiDuByDate(DateTime startTime, DateTime endTime, string sessionKey, bool isContainALLDate)
        {
            List<ManYiDuDateEntity> manYiDuDateEntityList = new List<ManYiDuDateEntity>();
            var gridViewModel = new GridViewModelBusiness().GetTradeRateViewModel(sessionKey);

            gridViewModel.ForEach(item =>
            {
                double totoalComment = 0;


                ManYiDuDateEntity manYiDuDateEntity = new ManYiDuDateEntity();
                manYiDuDateEntity.OrderDate = item.OrderDate;
                manYiDuDateEntity.DefaultGoodComment = item.TradeRateList.Count(n =>
                {
                    if (n.Result == APIDescriptionConstant.TraderateGoodComment && n.Content.Contains(APIDescriptionConstant.TraderateDefaultComment))
                    {
                        return true;
                    }

                    return false;
                });

                manYiDuDateEntity.NonDefaultGoodComment = item.TradeRateList.Count(n =>
                {
                    if (n.Result == APIDescriptionConstant.TraderateGoodComment && !n.Content.Contains(APIDescriptionConstant.TraderateDefaultComment))
                    {
                        return true;
                    }

                    return false;
                });

                manYiDuDateEntity.NeutralComment = item.TradeRateList.Count(n =>
                {
                    return n.Result == APIDescriptionConstant.TraderateNeutralComment;
                });

                manYiDuDateEntity.BadComment = item.TradeRateList.Count(n =>
                {
                    return n.Result == APIDescriptionConstant.TraderateBadComment;
                });

                manYiDuDateEntity.SellerGoodCommentsReply = item.TradeRateList.Count(n =>
                {
                    if (n.Result.Contains(APIDescriptionConstant.TraderateGoodComment) && !string.IsNullOrEmpty(n.Reply))
                    {
                        return true;
                    }

                    return false;
                });

                manYiDuDateEntity.SellerGoodCommentsReply = item.TradeRateList.Count(n =>
                {
                    if (n.Result.Contains(APIDescriptionConstant.TraderateNeutralComment) && !string.IsNullOrEmpty(n.Reply))
                    {
                        return true;
                    }

                    return false;
                });

                manYiDuDateEntity.SellerGoodCommentsReply = item.TradeRateList.Count(n =>
                {
                    if (n.Result.Contains(APIDescriptionConstant.TraderateBadComment) && !string.IsNullOrEmpty(n.Reply))
                    {
                        return true;
                    }

                    return false;
                });

                totoalComment += manYiDuDateEntity.DefaultGoodComment;
                totoalComment += manYiDuDateEntity.NonDefaultGoodComment;
                totoalComment += manYiDuDateEntity.NeutralComment;
                totoalComment += manYiDuDateEntity.BadComment;

                manYiDuDateEntity.GoodCommentRate = Math.Round((manYiDuDateEntity.DefaultGoodComment + manYiDuDateEntity.NonDefaultGoodComment) / totoalComment * 100).ToString() + "%";
                manYiDuDateEntity.NeutralCommentRate = Math.Round(manYiDuDateEntity.NeutralComment / totoalComment * 100).ToString() + "%";
                manYiDuDateEntity.BadCommentRate = Math.Round(manYiDuDateEntity.BadComment / totoalComment * 100).ToString() + "%";

                manYiDuDateEntityList.Add(manYiDuDateEntity);
            });

            return manYiDuDateEntityList;
        }
    }
}
